import tooler from './tooler'

var map = {};
init();

function init(){
    var str = tooler.readData("map", "{}");
    map = JSON.parse(str);
    console.log(map, "map");
}

function save(link, reg){
    var key = getHost(link);
    map[key] = reg;
    tooler.saveData("map", JSON.stringify(map));
}

function read(link){
    var key = getHost(link);
    return map[key] || "";
}

function getHost(link){
    var t = link.match(/https?:\/\/.*?\//i);
    return t ? t[0] : link;
}

export default {
    save,
    read,
    getHost
}